/*
 * mp_crypt.cpp
 *
 *  Created on: Nov 9, 2014
 *      Author: marc
 */

#define MP_VERSION_MAJOR "0"
#define MP_VERSION_MINOR "06"

#include <cstdio>
#include <string.h>
#include <errno.h>
#include "mp_common.hpp"
//#include <alloc.h>

/** \enum
 *  L'ensemble des erreurs que cette librairie peut remonter
 */
enum mp_crypt_error {
	MP_CRYPTERR_NO_ERR = 1,                    //!< MP_CRYPTERR_NO_ERR
	MP_CRYPTERR_EMPTY_PUBLIC_STRING = -8892,   //!< MP_CRYPTERR_EMPTY_PUBLIC_STRING
	MP_CRYPTERR_TOO_LONG_PUBLIC_STRING = -8893,//!< MP_CRYPTERR_TOO_LONG_PUBLIC_STRING
	MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL = -8894//!< MP_CRYPTERR_LIBRARY_DEPENDANCY_FAIL
} e;

/**
 * La variable globale qui contient le code erreur
 */
mp_crypt_error mp_errno;
/**
 *
 * @param P  la référence au pointeur qui contient la chaine
 * @return enum mp_crypt_error
 */
signed int mp_getEncrypt(char *P) {
	signed int retval = 0;
	const char *k = "Bollocs";
	strcpy(P,k);
	if (strlen(P) == 0) {
		if (errno) {
			retval = errno;
		}
		else  {
			retval = mp_errno = MP_CRYPTERR_EMPTY_PUBLIC_STRING;
		}

	}
	else {
		if (strlen(P) >= 256) {
			if (errno) {
				retval = errno;
			}
			else  {
				retval = mp_errno = MP_CRYPTERR_TOO_LONG_PUBLIC_STRING;
			}

		}
	}
	return retval;
}
/**
 * Renvoi deux versions du numéro de version de cette bibliothèque C pour Linux
 * @param J pointeur vers un ensemble de pointeurs vers char
 * @return int toujours 1
 */int mp_getVersion(char **J) {
	 char k[2][256];
	 k[0][0] = '0';
	 k[0][1] = '0';
	 k[0][2] = '0';
	 k[0][3] = '0';
	 k[0][4] = '0';
	 k[0][5] = '0';
	 k[0][6] = '0';
	 k[0][7] = '0';
	 k[0][8] = '0';
	 int indxr = 0;

	 k[0][0 + 3] = '7';
	 //strcpy(k[0] + 4,"99");
	 strcpy(k[0] + 4,MP_VERSION_MAJOR);
	 strcpy(k[0] + 4,"99");
	 //strcpy(k[0] + strlen(MP_VERSION_MAJOR) +2 ,MP_VERSION_MINOR);
	/*void *tm;
	void *ty;
	char *oyy;
	tm = calloc(2,sizeof(char));
	ty = calloc(256,sizeof(char));*/
//	strcpy(k[0],(char *)strncat((char *)"Version",MP_VERSION_FULL_STR,255));
	//strcpy(k[0],(char *)strncat("Version"," 0.000",256));
	 strcpy(J[0],"Version 0.06");
	 indxr = 1;
//	strcpy(J[0 + (inn * sizeof(char))],"0.06 R5899");
	strcpy(J[0 + (indxr * sizeof(char))],k[0]);
	/*strcpy(oyy,"0.05");
	memcpy(d *)ty,(void *)oyy,256);
	tm = ty;*/
	mp_errno = MP_CRYPTERR_NO_ERR;
	return mp_errno;
}
int mp_getGrog(char *P) {
	const char *k = "Grog returns";
	strcpy(P,k);
	return 99;
}
